package prj5;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Race information.
 * @author xinruili
 * @version 2022-04-19
 */
public class RaceStatusData {
    private String raceName;
    private String caseNumber;
    private String deathNumber;
    private String cfr;
    private int cfraccuracy;

    /**
     * Constructor with parameters.
     * @param raceName the name of race,
     * @param caseNumber the namber of case,
     * @param deathNumber the name of death,
     * @author xinruili
     * @version 2022-04-19
     */
    public RaceStatusData(final String raceName,
                          final String caseNumber, final String deathNumber) {
        this.raceName = raceName;
        this.caseNumber = caseNumber;
        this.deathNumber = deathNumber;
        this.cfraccuracy = 40;
        if (caseNumber.equals("NA") || deathNumber.equals("NA")) {
            this.cfr = "-1";
            if (caseNumber.equals("NA")) {
                this.caseNumber = "-1";
            }
        }
        else {
            BigDecimal cases = new BigDecimal(this.caseNumber);
            BigDecimal deaths = new BigDecimal(this.deathNumber);
            BigDecimal divide = deaths.divide(
                    cases, cfraccuracy, BigDecimal.ROUND_HALF_UP);
            divide = divide.multiply(new BigDecimal("100"));
            this.cfr = new DecimalFormat("#.#").format(divide);
        }
    }

    /**
     * Returns the name of race.
     * @return the name of race
     * @author xinruili
     * @version 2022-04-19
     */
    public String getRaceName() {
        return raceName;
    }

    /**
     * Returns the number of cases.
     * @return the number of cases
     * @author xinruili
     * @version 2022-04-19
     */
    public String getCaseNumber() {
        return caseNumber;
    }

    /**
     * Returns the number of CFT.
     * @return the number of CFT
     * @author xinruili
     * @version 2022-04-19
     */
    public String getCfr() {
        return cfr;
    }

    /**
     * Returns the string of class.
     * @return the String
     * @author xinruili
     * @version 2022-04-19
     */
    @Override
    public String toString() {
        return "RaceStatusData{"
                + "raceName='" + raceName + '\''
                + ", caseNumber='" + caseNumber + '\''
                + ", deathNumber='" + deathNumber + '\''
                + ", CFR='" + cfr + '\''
                + ", CFRAccuracy=" + cfraccuracy
                + '}';
    }
}

